package com.yunxi.controller.finance;

import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.finance.pojo.FinanceProductCalculateVO;
import java.math.BigDecimal;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.core.web.ApiResult;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import com.yunxi.finance.service.FinanceProductDubboService;
import com.yunxi.finance.pojo.FinanceProductVO;

/**
 * <p>
 * 金融产品维护 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-12-02
 */
@RestController
@RequestMapping("/admin/finance/product")
@Api(tags = "FINANCE:product", description = "金融产品维护接口")
public class FinanceProductController {

    private static final Logger logger = LoggerFactory.getLogger(FinanceProductController.class);

    @Autowired
    FinanceProductDubboService financeProductDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询金融产品维护分页")
    public ApiResult page(FinanceProductVO financeProductVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil.ok(financeProductDubboService.findPageByVO(financeProductVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "根据方案类型查询金融产品")
    public ApiResult productListByPlanType(String planType, @CurrentUser LoginInfo info) {
        return ResponseUtil.ok(financeProductDubboService.productListByPlanType(planType, info));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个金融产品维护")
    public ApiResult load(@RequestParam String id) {
        return ResponseUtil.ok(financeProductDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存金融产品维护信息")
    public ApiResult save(@RequestBody FinanceProductVO financeProductVO) {
        return financeProductDubboService.saveOrUpdate(financeProductVO);
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除金融产品维护")
    public ApiResult del(@RequestBody List<String> ids) {
        financeProductDubboService.removeByIds(ids);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/institution")
    @ApiOperation(value = "查询金融机构下拉框")
    public ApiResult institutionList() {
        return ResponseUtil.ok(financeProductDubboService.findFinanceInstitutionDropDown());
    }

    @PostMapping("/calculate")
    @ApiOperation(value = "计算结果")
    public ApiResult calculate(@RequestBody FinanceProductCalculateVO calculateVO) {
        return financeProductDubboService.calculate(calculateVO);
    }

    @PostMapping("/qualification/calculate")
    @ApiOperation(value = "金融购车资质审核金融方案计算")
    public ApiResult qualificationCalculate(@RequestBody FinanceProductCalculateVO calculateVO) {
        calculateVO.setOneTimePriceA(BigDecimal.ZERO);
        calculateVO.setOneTimePriceB(BigDecimal.ZERO);
        //尾款使用比例计算
        calculateVO.setBalanceShow(1);
        return financeProductDubboService.calculate(calculateVO);
    }

    @GetMapping("/vehicle/price")
    @ApiOperation(value = "查询整车价格")
    public ApiResult queryVehiclePrice(String vehicleCode) {
        List<String> codes = new ArrayList<>();
        codes.add(vehicleCode);
        return financeProductDubboService.queryPrice("ZPRR", codes);
    }

    @PostMapping("/package/price")
    @ApiOperation(value = "查询选装包价格")
    public ApiResult queryPackagePrice(@RequestBody List<String> packageCode) {
        return financeProductDubboService.queryPrice("ZVAR", packageCode);
    }



    /*@PostMapping("/export")
    @ApiOperation(value = "导出excel")
    public Object export(@RequestParam Map<String, Object> params) {
        return ResponseUtil.ok(financeProductDubboService.findMapByList(params));
    }*/
}
